package com.keyinong.caizhengting.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.ImageButton;

import com.keyinong.caizhengting.R;

import java.util.Calendar;
import java.util.Random;

/**
 * @author：郑谦
 * @时间：2017-4-10 下午4:02:27
 * @类名：CommentActivity.java
 * @功能: 个人中心-评价
 */

public class CommentActivity extends Activity {

    private ImageButton ib_back;
    private WebView vb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//			getWindow().addFlags(
//					WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_comment);
        initRes();
    }

    @SuppressLint("SetJavaScriptEnabled")
    private void initRes() {
        SharedPreferences sp = getSharedPreferences("spReg",
                Context.MODE_PRIVATE);
        String token = sp.getString("data", "");
        ib_back = (ImageButton) findViewById(R.id.ib_back);
        vb = (WebView) findViewById(R.id.webView1);
        vb.getSettings().setJavaScriptEnabled(true);
        vb.getSettings().setDomStorageEnabled(true);
//		vb.getSettings().setBlockNetworkImage(false);
        Log.i("zq", "kinon-------" + generateRandomFilename());
        String url = "http://dcapi.kinontech.com/h5.html#/waiter/comment?token=" + token;
        Log.i("zq", "url-------" + url);
        vb.loadUrl(url);
        vb.reload();
        ib_back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 生成随机数
     */
    public String generateRandomFilename() {
        String RandomFilename = "";
        Random rand = new Random();//生成随机数
        int random = rand.nextInt();

        Calendar calCurrent = Calendar.getInstance();
        int intDay = calCurrent.get(Calendar.DATE);
        int intMonth = calCurrent.get(Calendar.MONTH) + 1;
        int intYear = calCurrent.get(Calendar.YEAR);
        String now = String.valueOf(intYear) + "" + String.valueOf(intMonth) + "" +
                String.valueOf(intDay) + "";


        RandomFilename = now + String.valueOf(random > 0 ? random : (-1) * random);
        Log.i("zq", "date---" + RandomFilename);
        return RandomFilename;
    }

}
